package com.itheima.mapper;

import com.itheima.bean.Classes;
import com.itheima.bean.Student;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface StudentMapper {

//    @Select("select distinct s.id,s.name,s.age,s.cid from student s,stu_cr sc where sc.sid=s.id")
    @Select("select * from student")
    @Results({
            @Result(property="id",column="id"),
            @Result(property="name",column="name"),
            @Result(property="age",column="age"),
            @Result(property="courses",column="id",
                    javaType = List.class,
                    many = @Many(select="com.itheima.mapper.CourseMapper.findBySid")
            ),
            @Result(property="classes",column="cid",
                    javaType = Classes.class,
                    one=@One(select="com.itheima.mapper.ClassesMapper.findById")
            ),

    })
    public List<Student> findAll();

    
    Integer save(Student stu);

    
    Integer update(Student stu);

    
    Integer delete(@Param("id") Integer id, @Param("name") String name);

    @Select("select * from student where cid=#{cid}")
    List<Student> findByCid(Integer cid);


}
